package com.hxy.health.platform.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxy.health.platform.dao.ProductMapper;
import com.hxy.health.platform.pojo.Product;
import com.hxy.health.platform.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    /**
     * 带有分页查询所有商品信息
     * @param pageSize
     * @param pageNum
     * @return
     */
    @Override
    public PageInfo<Product> getAll(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> products = productMapper.getAll();
        PageInfo pageInfo = new PageInfo(products);
        return pageInfo;
    }

    /**
     * 获取产品详细信息
     * @param id
     * @return
     */
    @Override
    public Product getById(Integer id) {
        return productMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询最新的产品
     * @return
     */
    @Override
    public List<Product> getNewProduct() {
        List<Product> products = productMapper.getNewProduct();
        return products;
    }

    /**
     * 根据条件查询
     * @param pageSize
     * @param pageNum
     * @param productName
     * @return
     */
    @Override
    public PageInfo<Product> searchProduct(Integer pageSize, Integer pageNum, String productName) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> products = productMapper.searchProduct(productName);
        PageInfo pageInfo = new PageInfo(products);
        return pageInfo;
    }


}
